#include "List.h"
#include <iostream>

// 重载 << 运算符以便打印 List 内容
template <typename T>
std::ostream& operator<<(std::ostream& os, const List<T>& lst) {
    for (const auto& elem : lst) {
        os << elem << " ";
    }
    return os;
}

int main() {
    // 测试默认构造函数
    List<int> defaultList;
    std::cout << "Default constructed list: " << defaultList << std::endl;

    // 测试列表初始化构造函数
    List<int> initList = {1, 2, 3, 4, 5};
    std::cout << "List constructed from initializer_list: " << initList << std::endl;

    // 测试拷贝构造函数
    List<int> copiedList(initList);
    std::cout << "Copied list: " << copiedList << std::endl;

    // 测试移动构造函数
    List<int> movedList(std::move(initList));
    std::cout << "Moved list: " << movedList << std::endl;

    // 测试赋值运算符
    List<int> assignedList;
    assignedList = movedList;
    std::cout << "Assigned list: " << assignedList << std::endl;

    // 测试移动赋值运算符
    List<int> newList;
    newList = std::move(copiedList);
    std::cout << "Moved and assigned list: " << newList << std::endl;

    // 测试插入操作
    List<int> lst = {1, 2, 3, 4, 5};
    auto it = lst.begin();
    for (int i = 0; i < 2; ++i) {
        ++it;
    }
    lst.insert(it, 99);
    std::cout << "List after insert: " << lst << std::endl;

    // 测试删除操作
    it = lst.begin();
    for (int i = 0; i < 2; ++i) {
        ++it;
    }
    lst.erase(it);
    std::cout << "List after erase: " << lst << std::endl;
    
    // 测试访问首尾元素
    lst.push_back(10);
    lst.push_front(20);
    std::cout << "Front element: " << lst.front() << std::endl;
    std::cout << "Back element: " << lst.back() << std::endl;
    std::cout << "List after push: " << lst << std::endl;
    
    // 测试迭代器
    std::cout << "Iterating through list: ";
    for (auto it = lst.begin(); it != lst.end(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << std::endl;
    
    // 测试清空操作
    lst.clear();
    std::cout << "List after clear: " << lst << std::endl;

    return 0; 
}